﻿using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Infrastructure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.MES.Customer.Application.Application
{
    /// <summary>
    /// 出库服务实现层
    /// </summary>
    public class OutboundApplication : BaseApplication<OutWarehouse>, IOutboundApplication
    {
        private readonly IOutboundRepository _outboundRepository;
        private readonly IProduceRepository _produceRepository;
        public OutboundApplication(IOutboundRepository outboundRepository, IProduceRepository produceRepository) : base(outboundRepository)
        {
            _outboundRepository = outboundRepository;
            _produceRepository = produceRepository;
        }

        /// <summary>
        /// 显示、分页、查询出库列表
        /// </summary>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="outTopic">出库主题</param>
        /// <returns> 显示、分页、查询出库列表</returns>
        public PageApiResut<OutWareHouseDto> GetOutWare(int pageSize, int pageIndex, string? outTopic)
        {
            return _outboundRepository.GetOutWare(pageSize, pageIndex, outTopic);
        }
        /// <summary>
        /// 查看出库详情
        /// </summary>
        /// <param name="outId">出库编号</param>
        /// <returns>出库详情</returns>
        public APIResult<OutWareHouseDto> GetOutDetail(int outId)
        {
            return _outboundRepository.GetOutDetail(outId);
        }
        /// <summary>
        /// 添加出库信息并更改生产单状态
        /// </summary>
        /// <param name="outTab">出库表</param>
        /// <param name="proCode"> 生产单编号</param>
        /// <returns> 受影响行数</returns>
        public int AddOutTab(OutTabDto outTab, string proCode)
        {
           return _outboundRepository.AddOutTab(outTab, proCode);
        }
        /// <summary>
        /// 获取仓库树形图
        /// </summary>
        /// <param name="pid">父级ID</param>
        /// <returns>仓库树形图</returns>
        public List<WareHouseDto> GetWarehousesList(int pid)
        {
            return _outboundRepository.GetWarehousesList(pid);
        }
        /// <summary>
        /// 编辑出库信息
        /// </summary>
        /// <param name="outId">出库表主键</param>
        /// <returns>返回出库实体</returns>
        public OutTab GetOutTabById(int outId)
        {
            return _outboundRepository.GetOutTabById(outId);
        }
        /// <summary>
        /// 修改出库信息
        /// </summary>
        /// <param name="outTab">要添加的 出库信息对象</param>
        /// <returns> 受影响行数</returns>
        public int UpdOutInfoById(OutTab outTab)
        {
            return _outboundRepository.UpdOutInfoById(outTab);
        }
        /// <summary>
        /// 删除出库信息
        /// </summary>
        /// <param name="outId">出库主键</param>
        /// <returns>受影响行数</returns>
        public int DelOutById(int outId)
        {
            return _outboundRepository.DelOutById(outId);
        }
        /// <summary>
        /// 导出出库信息
        /// </summary>
        /// <returns> 显示、分页、查询出库列表</returns>
        public List<OutWareHouseDto> GetOutWareExport()
        {
          return _outboundRepository.GetOutWareExport();
        }
        /// <summary>
        /// 生产的显示分页查询
        /// </summary>
        /// <param name="ProCode">生产单号</param>
        /// <param name="pageIndex">当前是第几页</param>
        /// <param name="pageSize">每页需要显示多少条数据</param>
        /// <returns>生产的查询显示分页</returns>
        public PageApiResut<Produce> GetProduceShow(string? ProCode, int pageIndex, int pageSize)
        {
           return _outboundRepository.GetProduceShow(ProCode, pageIndex, pageSize);
        }
    }
}
